package com.idreems.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.idreems.mm.R;
import com.idreems.model.JsonItem;

public class SummaryListAdapter extends BaseAdapter
{
	private Context mContext;

	private ArrayList<JsonItem> mItems = new ArrayList<JsonItem>();

	public SummaryListAdapter(Context context, ArrayList<JsonItem> items)
	{
		super();
		mContext = context;
		if (items!=null && items.size()>0)
		{
			mItems.addAll(items);
		}
	}

	@Override
	public int getCount()
	{
		return mItems != null ? mItems.size() : 0;
	}

	@Override
	public Object getItem(int position)
	{
		return (mItems != null && mItems.size() > 0 && mItems.size() > position) ? mItems.get(position) : null;
	}

	@Override
	public long getItemId(int position)
	{
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		View view = convertView;
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (view == null)
		{
			view = inflater.inflate(R.layout.summary_list_item, null);
		}
		// TODO::TBC
		JsonItem item = mItems.get(position);
		String title = item.title;
		float fontSize = 18;
		String subscriptionTitle = item.author+"\t"+item.date;

		final ImageView imgState = (ImageView) view.findViewById(R.id.ItemState);
		final TextView txtTitle = (TextView) view.findViewById(R.id.Title);
		final TextView txtSubTitle = (TextView) view.findViewById(R.id.SubscriptionTitle);
		txtTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);
		txtTitle.setText(title);
		txtSubTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5);
		txtSubTitle.setText(subscriptionTitle);
		imgState.setImageResource(R.drawable.unread_sign);
		txtTitle.setTypeface(null, Typeface.BOLD);
		return view;
	}

}
